package com.gxa.service.impl.system;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gxa.mapper.system.MaterialMapper;
import com.gxa.mapper.system.UserMapper;
import com.gxa.pojo.entity.system.Material;
import com.gxa.pojo.entity.system.User;
import com.gxa.service.system.MaterialService;
import com.gxa.service.system.UserService;
import com.gxa.utils.Md5Utils;
import com.gxa.utils.QueryResult;
import com.gxa.utils.UserThreadLocal;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lch
 * @Date 2024/2/22 15:52
 * @Description
 **/
@Service
public class MaterialServiceImpl implements MaterialService {

    @Resource
    private MaterialMapper materialMapper;

    @Override
    public int addMaterial(Material material) {
        User user = UserThreadLocal.getUser();
        //设置登记人（当前登录用户）
        material.setRegistrant(user.getUserName());
        return materialMapper.insert(material);
    }

    @Override
    public Integer updateMaterial(Material material) {
        return materialMapper.update(material);
    }

    @Override
    public Integer deleteMaterialById(Integer id) {
        return materialMapper.delete(id);
    }

    @Override
    public QueryResult queryMaterial(Material material) {
        Page<Material> page = PageHelper.startPage(material.getPage(), material.getLimit());
        List<Material> materialList = materialMapper.query(material);
        QueryResult queryResult = new QueryResult();
        queryResult.setData(materialList);
        queryResult.setCount(page.getTotal());
        return queryResult;
    }
}
